package net.yxsoft.kit;

import com.jfinal.weixin.sdk.utils.JsonUtils;

import java.io.Serializable;
import java.util.HashMap;

public class MiniTemplateData implements Serializable {

  private static final long serialVersionUID = 1038149984818112449L;
  private String touser;
  private String template_id;
  private String page;
  private String form_id;

  private MiniTemplateData.MiniTemplateItem data = new MiniTemplateData.MiniTemplateItem();

  public static MiniTemplateData New() {
    return new MiniTemplateData();
  }

  private MiniTemplateData() {
  }

  public String getTouser() {
    return this.touser;
  }

  public MiniTemplateData setTouser(String touser) {
    this.touser = touser;
    return this;
  }

  public String getTemplate_id() {
    return this.template_id;
  }

  public MiniTemplateData setTemplate_id(String template_id) {
    this.template_id = template_id;
    return this;
  }

  public String getForm_id() {
    return this.form_id;
  }

  public MiniTemplateData setForm_id(String form_id) {
    this.form_id = form_id;
    return this;
  }

  public String getPage() {
    return this.page;
  }

  public MiniTemplateData setPage(String page) {
    this.page = page;
    return this;
  }

  public MiniTemplateData.MiniTemplateItem getData() {
    return this.data;
  }

  public MiniTemplateData add(String key, String value, String color) {
    this.data.put(key, new MiniTemplateData.Item(value, color));
    return this;
  }

  public MiniTemplateData add(String key, String value) {
    this.data.put(key, new MiniTemplateData.Item(value));
    return this;
  }

  public String build() {
    return JsonUtils.toJson(this);
  }

  public class Item {
    private Object value;
    private String color;

    public Object getValue() {
      return this.value;
    }

    public void setValue(Object value) {
      this.value = value;
    }

    public String getColor() {
      return this.color;
    }

    public void setColor(String color) {
      this.color = color;
    }

    public Item(Object value) {
      this(value, "#999");
    }

    public Item(Object value, String color) {
      this.value = value;
      this.color = color;
    }
  }

  public class MiniTemplateItem extends HashMap<String, MiniTemplateData.Item> {
    private static final long serialVersionUID = -3728490424738325020L;

    public MiniTemplateItem() {
    }

    public MiniTemplateItem(String key, MiniTemplateData.Item item) {
      this.put(key, item);
    }
  }
}
